package test.处理;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import utils.DbUtils;
import utils.SmallTool;

import java.util.List;

/**
 * @Author: gcr
 * @Date: 2022年5月14日13:52:18
 */
public class 比对老板网页数据单独比对出版时间入库20220515 {

    @SneakyThrows
    public static void main(String[] args) {
        // 下面代码是入库日志文件
//        SmallTool.printMemory();
//        DSFactory.setCurrentDSFactory(new DruidDSFactory());
//        DataSource ds = DSFactory.get("server_my");
//        Db use = Db.use(ds);
        String dbNameMy = "pmid_date_compare";
//
//        List<String> strings = FileUtil.readLines("/usr/local/20220514/比对出版年记录.log", "UTF-8");
//
//        for (String string : strings) {
//            String[] split = string.split("\\+\\+pmid\\+\\+");
//            Integer pmid = Integer.parseInt(split[1]);
//            String meDate = split[0].split("meyear")[1].replace("++", "");
//            String meYear = meDate.split("memedline")[0];
//            String meYearmedLine = "";
//            try {
//                meYearmedLine = meDate.split("memedline")[1];
//
//            } catch (Exception e) {
//
//            }
//            String bossDate = split[0].split("boss")[1].substring(2, split[0].split("boss")[1].indexOf("++meyear"));
//            Entity entity = new Entity();
//            entity.setTableName(dbNameMy);
//            entity.set("pmid", pmid);
//            entity.set("me", meYear);
//            entity.set("me_medline", meYearmedLine);
//            entity.set("boss", bossDate);
//            use.insert(entity);
//        }

        // 进行把数据库里面的medlinedata 进行比对

        int effectSize = 0;

        int startPmid = 0;
        int endPmid = 35000000;
        int breakSize = 10000;

        SmallTool.printMemory();
        Db use3307 = DbUtils.getCorrect();


        String allDate = "select max(id) as ids  from " + dbNameMy;
        Entity query = use3307.query(allDate).get(0);
        SmallTool.printMess("最大的id 是" + query.getStr("ids"));


        Integer count = query.getInt("ids");
        int pageSize = count / breakSize + 1;
        SmallTool.printMess("全部页码+++++++++" + pageSize);
        SmallTool.printMess("任务开始+++++++++++++++++++++++++++++++++++++++++++++++++++++");

        // 比对数量
        Integer compare = 0;
        // medline相同的
        Integer sameMedlincompare = 0;
        // -分割后相同
        Integer samesplitfirst = 0;
        // medline 含有-
        Integer sameMedlincomparecontains = 0;
        // medline 不含有-
        Integer sameMedlincomparenocontains = 0;
        // medline 不同
        Integer nosameMedlincompare = 0;
        // 老板时间是空
        Integer bossEmpty = 0;
        for (int i = 1; i <= pageSize; i++) {
            int start = breakSize * (i - 1) + 1;
            int end = i * breakSize;
            SmallTool.printMess("开始id++" + start + "+++结束id++++" + end);

            String meSql = "select *  from " + dbNameMy + " where id between " + start + " and " + end;
            List<Entity> queryMe = use3307.query(meSql);
            // 相比对 doi pmid 标题
            for (Entity pmDeatil : queryMe) {
                compare++;
                String pmid = pmDeatil.getStr("pmid");
                Integer id = pmDeatil.getInt("id");
                String me = pmDeatil.getStr("me");
                String me_medline = pmDeatil.getStr("me_medline");
                String boss = pmDeatil.getStr("boss");
                String me_sp = pmDeatil.getStr("me_sp");
                String boss_sp = pmDeatil.getStr("boss_sp");
                Entity where = new Entity();
                where.setTableName(dbNameMy);
                where.set("id", id);

                // 默认没有判断
                boolean ischeck = true;
                // 中间测试 都含有- 情况进行判断
                if (StringUtils.isNotEmpty(me_sp) && StringUtils.isNotEmpty(boss_sp)) {
                    if (me_medline.contains("-") && boss.contains("-")) {
                        ischeck = false;
                        if (me_sp.equals(boss_sp)) {
                            use3307.del(where);

                        } else {
                            System.out.println("都存在 默认首年 不一样出现了++pmid++" + pmid);
                        }

                    }
                }

                // 不含有- 情况判断
                if (ischeck && StringUtils.isNotEmpty(me_medline) && StringUtils.isNotEmpty(boss)) {
                    if (!me_medline.contains("-") && !boss.contains("-")) {
                        ischeck = false;
                        if (me_medline.equals(boss)) {
//                            use3307.del(where);
                        } else {
                            System.out.println("都存在 默认不含- 不一样出现了++pmid++" + pmid);
                        }

                    }
                }


//                if (ischeck) {
//                    if (StringUtils.isEmpty(boss)) {
//                        use3307.del(where);
//                    }
//                    if (me_sp.equals(boss_sp)) {
//                        samesplitfirst++;
//                    } else {
//                        SmallTool.printMessError("sp分割后第一个不相同++pmid++" + pmid);
//                    }
//                }


//                if (StringUtils.isEmpty(boss) || boss.equals("kong")) {
//                    bossEmpty++;
//                } else {
//                    if (!me.equals(boss)) {
//                        if (me_medline.equals(boss)) {
//                            sameMedlincompare++;
//                            if (me_medline.contains("-")) {
//                                sameMedlincomparecontains++;
//                            } else {
//                                SmallTool.printMessError("++pmid++gcr++" + pmid + "++me++" + me + "++memedline++" + me_medline + "++boss++" + boss);
//                                sameMedlincomparenocontains++;
//                            }
//                        } else {
//                            nosameMedlincompare++;
////                            SmallTool.printMessError("++pmid++" + pmid + "++me++" + me + "++memedline++" + me_medline + "++boss++" + boss);
//                        }
//                    }
//                }
            }
        }
        SmallTool.printMess("比对结束++全部比对数量++" + compare + "++medline相同的++" + sameMedlincompare + "++medline时间含有-++" + sameMedlincomparecontains + "++medline时间不含有-++" + sameMedlincomparenocontains + "++medline不同的++" + nosameMedlincompare + "++老板时间是空的+" + bossEmpty);
        SmallTool.printMess("比对结束++全部比对数量++" + compare + "++sp分割后相同++" + samesplitfirst);

    }

}
//                if (me_medline.contains("-")) {
//                    me_sp = me_medline.split("-")[0];
//                }
//
//                if (boss.contains("-")) {
//                    boss_sp = boss.split("-")[0];
//                }
//                pmDeatil.set("me_sp", me_sp);
//                pmDeatil.set("boss_sp", boss_sp);
//                Entity where = new Entity();
//                where.set("id", id);
//                where.setTableName(dbNameMy);
//                use3307.update(pmDeatil, where);